home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bluep.swf / scripts / __Packages / mx / transitions / Tween.as < prev   
Text File  |  2013-04-24  |  5KB  |  226 lines

  1. class mx.transitions.Tween
  2. {
  3.    static var version = "1.1.0.52";
  4.    static var __initBeacon = mx.transitions.OnEnterFrameBeacon.init();
  5.    static var __initBroadcaster = mx.transitions.BroadcasterMX.initialize(mx.transitions.Tween.prototype,true);
  6.    function Tween(obj, prop, func, begin, finish, duration, useSeconds)
  7.    {
  8.       mx.transitions.OnEnterFrameBeacon.init();
  9.       if(!arguments.length)
  10.       {
  11.          return undefined;
  12.       }
  13.       this.obj = obj;
  14.       this.prop = prop;
  15.       this.begin = begin;
  16.       this.__set__position(begin);
  17.       this.__set__duration(duration);
  18.       this.useSeconds = useSeconds;
  19.       if(func)
  20.       {
  21.          this.func = func;
  22.       }
  23.       this.__set__finish(finish);
  24.       this._listeners = [];
  25.       this.addListener(this);
  26.       this.start();
  27.    }
  28.    function set time(t)
  29.    {
  30.       this.prevTime = this._time;
  31.       if(t > this.__get__duration())
  32.       {
  33.          if(this.looping)
  34.          {
  35.             this.rewind(t - this._duration);
  36.             this.update();
  37.             this.broadcastMessage("onMotionLooped",this);
  38.          }
  39.          else
  40.          {
  41.             if(this.useSeconds)
  42.             {
  43.                this._time = this._duration;
  44.                this.update();
  45.             }
  46.             this.stop();
  47.             this.broadcastMessage("onMotionFinished",this);
  48.          }
  49.       }
  50.       else if(t < 0)
  51.       {
  52.          this.rewind();
  53.          this.update();
  54.       }
  55.       else
  56.       {
  57.          this._time = t;
  58.          this.update();
  59.       }
  60.    }
  61.    function get time()
  62.    {
  63.       return this._time;
  64.    }
  65.    function set duration(d)
  66.    {
  67.       this._duration = !(d == null || d <= 0) ? d : _global.Infinity;
  68.    }
  69.    function get duration()
  70.    {
  71.       return this._duration;
  72.    }
  73.    function set FPS(fps)
  74.    {
  75.       var _loc2_ = this.isPlaying;
  76.       this.stopEnterFrame();
  77.       this._fps = fps;
  78.       if(_loc2_)
  79.       {
  80.          this.startEnterFrame();
  81.       }
  82.    }
  83.    function get FPS()
  84.    {
  85.       return this._fps;
  86.    }
  87.    function set position(p)
  88.    {
  89.       this.setPosition(p);
  90.    }
  91.    function setPosition(p)
  92.    {
  93.       this.prevPos = this._pos;
  94.       this.obj[this.prop] = this._pos = p;
  95.       this.broadcastMessage("onMotionChanged",this,this._pos);
  96.       updateAfterEvent();
  97.    }
  98.    function get position()
  99.    {
  100.       return this.getPosition();
  101.    }
  102.    function getPosition(t)
  103.    {
  104.       if(t == undefined)
  105.       {
  106.          t = this._time;
  107.       }
  108.       return this.func(t,this.begin,this.change,this._duration);
  109.    }
  110.    function set finish(f)
  111.    {
  112.       this.change = f - this.begin;
  113.    }
  114.    function get finish()
  115.    {
  116.       return this.begin + this.change;
  117.    }
  118.    function continueTo(finish, duration)
  119.    {
  120.       this.begin = this.position;
  121.       this.__set__finish(finish);
  122.       if(duration != undefined)
  123.       {
  124.          this.__set__duration(duration);
  125.       }
  126.       this.start();
  127.    }
  128.    function yoyo()
  129.    {
  130.       this.continueTo(this.begin,this.__get__time());
  131.    }
  132.    function startEnterFrame()
  133.    {
  134.       if(this._fps == undefined)
  135.       {
  136.          _global.MovieClip.addListener(this);
  137.       }
  138.       else
  139.       {
  140.          this._intervalID = setInterval(this,"onEnterFrame",1000 / this._fps);
  141.       }
  142.       this.isPlaying = true;
  143.    }
  144.    function stopEnterFrame()
  145.    {
  146.       if(this._fps == undefined)
  147.       {
  148.          _global.MovieClip.removeListener(this);
  149.       }
  150.       else
  151.       {
  152.          clearInterval(this._intervalID);
  153.       }
  154.       this.isPlaying = false;
  155.    }
  156.    function start()
  157.    {
  158.       this.rewind();
  159.       this.startEnterFrame();
  160.       this.broadcastMessage("onMotionStarted",this);
  161.    }
  162.    function stop()
  163.    {
  164.       this.stopEnterFrame();
  165.       this.broadcastMessage("onMotionStopped",this);
  166.    }
  167.    function resume()
  168.    {
  169.       this.fixTime();
  170.       this.startEnterFrame();
  171.       this.broadcastMessage("onMotionResumed",this);
  172.    }
  173.    function rewind(t)
  174.    {
  175.       this._time = t != undefined ? t : 0;
  176.       this.fixTime();
  177.       this.update();
  178.    }
  179.    function fforward()
  180.    {
  181.       this.__set__time(this._duration);
  182.       this.fixTime();
  183.    }
  184.    function nextFrame()
  185.    {
  186.       if(this.useSeconds)
  187.       {
  188.          this.__set__time((getTimer() - this._startTime) / 1000);
  189.       }
  190.       else
  191.       {
  192.          this.__set__time(this._time + 1);
  193.       }
  194.    }
  195.    function onEnterFrame()
  196.    {
  197.       this.nextFrame();
  198.    }
  199.    function prevFrame()
  200.    {
  201.       if(!this.useSeconds)
  202.       {
  203.          this.__set__time(this._time - 1);
  204.       }
  205.    }
  206.    function toString()
  207.    {
  208.       return "[Tween]";
  209.    }
  210.    function fixTime()
  211.    {
  212.       if(this.useSeconds)
  213.       {
  214.          this._startTime = getTimer() - this._time * 1000;
  215.       }
  216.    }
  217.    function update()
  218.    {
  219.       this.__set__position(this.getPosition(this._time));
  220.    }
  221.    function func(t, b, c, d)
  222.    {
  223.       return c * t / d + b;
  224.    }
  225. }
  226.